﻿/*
 * RenderableLegendNodeBase
 * 
 * initial implementation : 12.12.2008
 *
 * Copyright (c) Adam Sida, asida@centrum.cz.
 * All rights reserved.
 * 
 * for license see Petra.Gis.License.txt
 */
using System;
using System.Collections.Generic;
using Petra.Gis.DataServices;
using Petra.Gis.DataServices.Metadata;
using Petra.Gis.ReferenceSystemServices.Transformations;


namespace Petra.Gis.RenderingServices.PlanarBase
{


  /// <summary>
  /// represents legend node which can render into map at output format
  /// </summary>
  public abstract class RenderableLegendNodeBase : LegendNodeBase
  {


    #region ctor

    protected RenderableLegendNodeBase()
      :base()
    { }




    protected RenderableLegendNodeBase(LeafLegendNode parent, string title)
      : base(parent, title)
    { }

    #endregion ctor



    /// <summary>
    /// data node data
    /// </summary>
    protected abstract IFeatureSet featureSet { get; set; }



    /// <summary>
    /// data node data, use new to replace in inherited...
    /// </summary>
    public IFeatureSet FeatureSet
    {
      get { return featureSet; }
      set { featureSet = value; }
    }



    /// <summary>
    /// get/set data legend node display order for DisplayOrder collection
    /// </summary>
    public int DisplayOrder { get; set; }




    /// <summary>
    /// starts to render data defined by this legend entry into map.
    /// Must override in inherited classes.
    /// </summary>
    public abstract void RenderData();




    /// <summary>
    /// prepare spatial filter for data
    /// if spatialcommand refers to data with more than 1 spatial fiels
    /// spatial filter must be defined with name for spatial field
    /// </summary>
    /// <returns></returns>
    protected virtual FeatureSpatialFilter createSpatialFilter()
    {
      SpatialFieldMetadata gfm = featureSet.Metadata.GeometryFieldsMetadata[0];
      SRSTransform t = this.Legend.Map.SRSTransformCache.GetTransform(gfm.SRS, true);
      FeatureSpatialFilter spatialFilters = new FeatureSpatialFilter()
      {
        SpatialFieldName = gfm.Name,
        Bounds = t.TransformBox(this.Legend.Map.ProjectionExtent)
      };

      //foreach (SpatialFieldMetadata gfm in _data.Metadata.GeometryFieldsMetadata)
      //{
      //  // prepare reverse transform for this geometry field coordinate system...
      //  SRSTransform t = this.Legend.Map.SRSTransformCache.GetTransform(gfm.SRS, true);
      //  spatialFilters.Add(gfm.Name, t.TransformBox(this.Legend.Map.ProjectionExtent));
      //}

      return spatialFilters;
    }
  }

}
